package com.cgnpc.scp.sri.laboratory.controller;

import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.result.ApiResult;
import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.scp.achievement.pojo.IdReq;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.common.utils.StringUtil;
import com.cgnpc.scp.hse.controller.HseCheckOptionsConfigController;
import com.cgnpc.scp.sri.laboratory.mybatis.entity.LaboratoryAnnualPlan;
import com.cgnpc.scp.sri.laboratory.mybatis.entity.LaboratoryAnnualPlanPhase;
import com.cgnpc.scp.sri.laboratory.pojo.LaboratoryAnnualPlanPhaseVo;
import com.cgnpc.scp.sri.laboratory.pojo.LaboratoryAnnualPlanVo;
import com.cgnpc.scp.sri.laboratory.service.LaboratoryAnnualPlanPhaseService;
import com.cgnpc.scp.sri.laboratory.service.LaboratoryAnnualPlanService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**********************************
 * 用途说明: 实验室年度计划管理
 * 作者姓名: zhangyibing
 * 创建时间: 2020年10月4日22:01:04
 ***********************************/
@RestController
@RequestMapping("/scp/sri/laboratoryAnnualPlan/phase")
public class LaboratoryAnnualPlanPhaseController {
    private static final Logger LOGGER = LoggerFactory.getLogger(LaboratoryAnnualPlanPhaseController.class);

    @Autowired
    private MessageSource messageSource;

    @Autowired
    private LaboratoryAnnualPlanPhaseService laboratoryAnnualPlanPhaseService;

    /**********************************
     * 用途说明: 调试科研创新管理 - 能力建设计划管理 - 根据计划id获取所有项目阶段
     * 参数说明 params
     * 返回值说明: 项目阶段
     ***********************************/
    @ApiOperation(value="调试科研创新管理 - 能力建设计划管理 - 根据计划id获取所有项目阶段")
    @RequestMapping(value = "/getPhaseByPlanId", method = {RequestMethod.POST})
    public AjaxResult getPhaseByPlanId(HttpServletRequest request, @RequestBody Map<String, String> params) {
        try {
            String planId = params.get("planId");
            if(StringUtil.isNullOrSpace(planId)){
                return AjaxResult.error("planId can not be null");
            }
            List<LaboratoryAnnualPlanPhase> result = laboratoryAnnualPlanPhaseService.getPhaseByPlanId(planId);
            return AjaxResult.success().put("data",result);
        } catch (Exception e) {
            LOGGER.error("LaboratoryAnnualPlanPhaseController getPhaseByPlanId error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 阶段进展 - 阶段详情
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/stageInfo")
    @ApiOperation(value="阶段进展-阶段详情")
    public AjaxResult stageInfo(HttpServletRequest request,@RequestBody IdReq idReq) {
        try {
            LaboratoryAnnualPlanPhaseVo phaseVo = laboratoryAnnualPlanPhaseService.stageInfo(idReq.getId());
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,phaseVo);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("LaboratoryAnnualPlanController stageSubmitProcess error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 阶段进展 - 阶段进展详情
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/progressInfo")
    @ApiOperation(value="阶段进展-阶段进展详情")
    public AjaxResult progressInfo(HttpServletRequest request,@RequestBody IdReq idReq) {
        try {
            LaboratoryAnnualPlanPhaseVo phaseVo = laboratoryAnnualPlanPhaseService.progressInfo(idReq.getId());
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,phaseVo);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("LaboratoryAnnualPlanController stageSubmitProcess error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 调试科研创新管理 - 实验室计划管理 - 进展提交（提交流程或存草稿）
     * 参数说明 params
     * 返回值说明: 能建列表
     ***********************************/
    @ApiOperation(value="调试科研创新管理 - 实验室计划管理 - 进展提交")
    @RequestMapping(value = "/planStageSave", method = {RequestMethod.POST})
    public AjaxResult planStageSave(HttpServletRequest request, @RequestBody Map<String, Object> params) {
        try {
            AjaxResult result = laboratoryAnnualPlanPhaseService.planStageSave(params);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
        } catch (Exception e) {
            LOGGER.error("LaboratoryAnnualPlanController planStageSave error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 阶段进展 - 提交/回退流程
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/stageSubmitProcess")
//    @UBA(module = "能力建设计划管理", action = "能力建设计划管理阶段进展审批流程提交/回退", channel = OperatorType.Button)
    @ApiOperation(value="阶段进展提交/回退流程")
    public AjaxResult stageSubmitProcess(HttpServletRequest request,@RequestBody Map<String, Object> params) {
        try {
            ApiResult apiResult = laboratoryAnnualPlanPhaseService.stageSubmitProcess(params);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,apiResult);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error("LaboratoryAnnualPlanController stageSubmitProcess error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 实验室年度计划管理 - 实验室计划进展删除草稿
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="实验室年度计划管理 - 实验室计划进展删除草稿")
    @UBA(module = "实验室年度计划管理", action = "实验室计划进展删除草稿", channel = OperatorType.Page)
    @RequestMapping(value = "/deleteProcessDraft", method = {RequestMethod.POST})
    public AjaxResult deleteProcessDraft(HttpServletRequest request, @RequestBody Map<String, Object> params) throws Exception {
        ApiResult result = laboratoryAnnualPlanPhaseService.deleteProcessDraft(params);
        return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
    }

}
